﻿/*******************************************************************
Copyright (c) 2011 이재범

*  Permission is hereby granted, free of charge, to any person
*  obtaining a copy of this software and associated documentation
*  files (the "Software"), to deal in the Software without
*  restriction, including without limitation the rights to use,
*  copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the
*  Software is furnished to do so, subject to the following
*  conditions:
* 
*  The above copyright notice and this permission notice shall be
*  included in all copies or substantial portions of the Software.
* 
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
*  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*  OTHER DEALINGS IN THE SOFTWARE.
*******************************************************************/

#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#pragma once

using namespace std;

// lu_decomposition.cpp
int calculate_determinant(int** relation_matrix, int dim);

// common.cpp
int find_match_parenth(int i, string &equation);
int find_real_match_parenth(int i, string &equation);
int search_vec(vector<string> &str, string what);
int search_vec(vector<string> &str, char c);
void remove_space(string &str);
void remove_space(vector<string> &str);
string vector_to_string(vector<string> &list);
bool compare_vector(vector<string> &str1, vector<string> &str2);
void optimize_braket(string &equation);
void remove_escape_character(string &equation);
string double_to_string(double x);
string convert_num_to_string(int i);
int find_outer_close_parenth(int i, string &equation);
int find_outer_open_parenth(int i, string &equation);
bool is_digit(int c);
bool is_alpha(int c);
wstring string_to_wstring_conv(string &str);
string wstring_to_string_conv(wstring &wstr);

template <typename T> 
void print_vector(vector<T> &str)
{
	int i = 0;
	while (i < static_cast<int>(str.size()))
	{
		cout <<" / " << str[i];
		i ++;
	}
	cout << endl;
}

template <typename T> 
string convert_to_string(const T& t)
{
	std::stringstream str_out;
	str_out << t;
	return str_out.str();
}

template <typename T>
bool search_vector(vector<T> &vec, T& find)
{
	vector<T>::iterator itr = vec.begin();

	while (itr != vec.end())
	{
		if(*itr == find)
			return true;

		itr ++;
	}
	return false;
}

template <typename T>
void extract_string_btw(T &list, T left, T right, vector<T> &result) // left 와 right 로 둘러쌓인 문자열을 list 에서 추출
{
	T::size_type location = list.find(left);

	while (location != list.npos)
	{
		T::size_type find = location + left.length();
		T::size_type end_find = list.find(right, find);

		if(end_find != list.npos)
		{
			result.push_back(list.substr(find, end_find - find));
			location = list.find(left, end_find + 1);
		}
		else
			break;

	}

}
